package com.zhr.tea.view.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.zhr.tea.R;
import com.zhr.tea.view.adapter.ChaQuanViewpagerAdapter;
import com.zhr.tea.view.fragment.GuanzhuFragment;
import com.zhr.tea.view.fragment.RemenFragment;
import com.zhr.tea.view.fragment.ZuixinFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChaQuanActivity extends AppCompatActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tab_chaquan)
    TabLayout tabChaquan;
    @BindView(R.id.vp_chaquan)
    ViewPager vpChaquan;
    private List<Fragment> data = new ArrayList<>();
    private ChaQuanViewpagerAdapter adapter;
    private String[] title = new String[]{"热门话题", "最新话题", "关注话题"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cha_quan);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    private void initData() {
        data.add(RemenFragment.newInstance());
        data.add(ZuixinFragment.newInstance());
        data.add(GuanzhuFragment.newInstance());
        adapter.notifyDataSetChanged();
    }

    private void initView() {

        adapter = new ChaQuanViewpagerAdapter(getSupportFragmentManager(), data, title);
        vpChaquan.setAdapter(adapter);
        tabChaquan.setupWithViewPager(vpChaquan);
    }

    @OnClick(R.id.iv_back)
    public void onClick() {
        finish();
    }
}
